<?php
  $id = "" .$_GET['id'];
  $data = array('20' => 'chair',
                '300' => 'pencli',
                '100' => 'book',
                '00' => 'monitor',
                '6371' => 'book');

  $cost = array('20' => '5000',
                '300' => '1000',
                '100' => '13000',
                '00' => '150000',
                '6371' => '1000');

  $count = array('20' => '1',
                '300' => '1',
                '100' => '1',
                '00' => '1',
                '6371' => '1');

  
  $con = mysql_connect("mysql1.000webhost.com", "a7424976_info", "thebest5");
	$res = mysql_select_db("a7424976_info");
	
	$q1 = mysql_query("select * from mode");
  $r1 = mysql_fetch_row($q1);
  
  $mode = (int)$r1[0];
  
  $mm = date("Y/m/d H:i:s", mktime(date("H"),date("i"),date("s"),date("m"), date("d"), date("Y")));
  
  $q2 = mysql_query("select * from inventory where id='$id' AND state=0");
  $q3 = mysql_query("select * from inventory where id='$id' AND state=1");
  $q5 = mysql_query("select id from inventory");
  
    
    
  if ($mode == 0){	    
    $a = 0;
    $q4 = mysql_query("insert into inventory values('$id', '$data[$id]', '$cost[$id]', '$count[$id]', '$mm', 0)");
    while($id == mysql_fetch_array($q5)){
       $a = 1;
      }
      if($a==0) {
      echo "stock";    
    }
    
  }
  else{
    if (mysql_num_rows($q2) - mysql_num_rows($q3) >= 0){
      $q4 = mysql_query("insert into inventory values('$id', '$data[$id]', '$cost[$id]', '0', '$mm', 1)");
      echo "delivery";
    }
  }
  
 	mysql_close($con);
 	
?>
